package com.spsoft.vatoutinv.service.vmsavalibletaxrate.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.spsoft.core.model.Result;
import com.spsoft.core.utils.BeanUtils;
import com.spsoft.vatoutinv.entity.vmsavalibletaxrate.VmsAvalibleTaxRateLogBase;
import com.spsoft.vatoutinv.enums.CommonEnum;
import com.spsoft.vatoutinv.mapper.VmsAvalibleTaxRateLogBaseMapper;
import com.spsoft.vatoutinv.model.dto.vmsavalibletaxrate.VmsAvalibleTaxRateLogBaseDto;
import com.spsoft.vatoutinv.model.vo.vmsavalibletaxrate.VmsAvalibleTaxRateLogBaseVo;
import com.spsoft.vatoutinv.service.vmsavalibletaxrate.VmsAvalibleTaxRateLogBaseService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 可用税率信息查询记录-主表 服务实现类
 * </p>
 *
 * @author chenxudong
 * @since 2023-11-23
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class VmsAvalibleTaxRateLogBaseServiceImpl extends ServiceImpl<VmsAvalibleTaxRateLogBaseMapper, VmsAvalibleTaxRateLogBase> implements VmsAvalibleTaxRateLogBaseService {

    private final VmsAvalibleTaxRateLogBaseMapper vmsAvalibleTaxRateLogBaseMapper;

    @Override
    public Result<IPage<VmsAvalibleTaxRateLogBaseVo>> queryVmsAvalibleTaxRateLog(VmsAvalibleTaxRateLogBaseDto vmsAvalibleTaxRateLogBaseDto) {
        // 获取分页数据
        Page<VmsAvalibleTaxRateLogBase> page = new Page<>(vmsAvalibleTaxRateLogBaseDto.getPageNo(), vmsAvalibleTaxRateLogBaseDto.getPageSize());
        IPage<VmsAvalibleTaxRateLogBase> IPage = vmsAvalibleTaxRateLogBaseMapper.queryVmsAvalibleTaxRateLog(page, vmsAvalibleTaxRateLogBaseDto);
        // 将数据库返回数据转换为VO返回前端
        IPage<VmsAvalibleTaxRateLogBaseVo> IPageVo = IPage.convert(item -> {
            VmsAvalibleTaxRateLogBaseVo vo = new VmsAvalibleTaxRateLogBaseVo();
            // 转换数据
            BeanUtils.copyBeanProp(vo, item);
            // 调用乐企结果为成功，不返回前端执行结果，防止operateMsg字段过长
            if (CommonEnum.LEQI_RETURN_CODE_SUCCESS.getKey().equals(item.getOperateStatus())) {
                vo.setOperateMsg(null);
            }
            return vo;
        });
        return Result.OK(IPageVo);
    }

}
